<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>teacherInfo</title>
    <link th:href="@{/webjars/bootstrap/3.4.1/css/bootstrap.css}" rel="stylesheet">
</head>
<body>
<div class="well well-lg" style="margin-left: 400px;margin-right: 400px">

    <p th:text="'姓名:'+${teacherName}" style="text-align: center">姓名</p>
    <p th:text="'共号:'+${teacherNo}" style="text-align: center">学号</p>
    <p th:text="'学校:'+${schoolName}" style="text-align: center">学校</p>
    <p th:text="'邮箱:'+${email}" style="text-align: center">邮箱</p>

</div>
<div style="text-align: center">
    <div class="form-group">
        <label class="col-auto">
            <input type="password" class="form-control" id="password" placeholder="请输入密码" style="width:200px">
        </label>
    </div>
    <div class="form-group">
        <label class="col-auto">
            <input type="password" class="form-control" id="newPassword1" placeholder="请输入修改密码" style="width:200px">
        </label>
    </div>
    <div class="form-group">
        <label class="col-auto">
            <input type="password" class="form-control" id="newPassword2" placeholder="请确认修改密码" style="width:200px">
        </label>
    </div>
    <div class="align-bottom col-auto">
        <button type="button" value="modifyPassword" class="btn btn-primary btn-sm" id="modifyPassword">修改密码</button>
    </div>
</div>
<script th:src="@{/webjars/jquery/3.4.1/jquery.js}"></script>
<script>
    $("#modifyPassword").click(function () {
        var password = $("#password").val();
        var newPassword1 = $("#newPassword1").val();
        var newPassword2 = $("#newPassword2").val();
        if(password != null && password != "" && newPassword1 != null && newPassword1 != "" && newPassword2 != null && newPassword2 != ""){
            if(newPassword1 == newPassword2){
                $.ajax({
                    type:"POST",
                    url:"/modifyPassword",
                    data:{
                        "password":password,
                        "newPassword":newPassword1
                    },
                    dataType:"json",
                    success:function (result) {
                        if (result.success == true) alert("修改成功");
                        else alert("密码错误");
                    },
                    error:function () {
                        alert("失败");
                    }
                })
            }else alert("修改密码不一致");
        }else alert("请先填满信息");
    })
</script>
</body>
</html>